<?

$uniqID = 'task'.$TASK->id.'-comments-provider';

$COMMENTS = $TASK->getRelated('comments');

$COMMENTSPROVIDER = new CArrayDataProvider($COMMENTS, array(
    'id' => $uniqID,
    'pagination'=>array( 'pageSize'=>3 )
));

$numCom = TaskComment::model()->countByAttributes(array('task_id'=>$TASK->id));

?>
    <a href="#comments-<?=$TASK->id?>" name="comments-<?=$TASK->id?>" onclick="$('#commentstask<?=$TASK->id?>').toggle(); return false;">Комментарии (<?=$numCom?>)</a>
    <div id="commentstask<?=$TASK->id?>" class="comments" style="display: <?=$display?>;">
        
        <div class="commentlist">
        <?$this->widget('zii.widgets.CListView', array(
            'dataProvider' => $COMMENTSPROVIDER,
            'id' => $uniqID,
            'itemView' => 'application.modules.task.views.task._list_comment_row',
            'viewData' => array(
                'TASK' => $TASK
            )
        ))?>
        </div>
        
        <?
        $formurl = $this->createUrl('tools/taskcommentsave', array('taskID'=>$TASK->id,'backurl'=>$_SERVER['REQUEST_URI']));
        ?>
        <a name="form-add-comment-task<?=$TASK->id?>"></a>
        <form class="form-add-comment" id="form-add-comment-task<?=$TASK->id?>" action="<?=$formurl?>" method="post">
        <input type="hidden" name="taskID" value="<?=$TASK->id?>" />
        <div class="form">
            <h3>Новый комментарий</h3>
            <div class="row">
                <textarea name="text" class="bigtext"></textarea>
            </div>
            <div class="row">
                <input type="submit" name="do_save" value="<?=TaskModule::t('app', 'Оставить комментарий')?>"
                    onclick="jQuery.ajax({ 'type':'POST', 'url':'<?=$formurl?>', 'cache':false,
                        'data':jQuery(this).parents('form').serialize(),
                        'success':function(html){ jQuery('#comments-wrapper-<?=$TASK->id?>').html(html); }
                        }); return false;
                    " />
            </div>
        </div>
        </form>
    </div>
